package com.ehsy.statement;

import com.dtflys.forest.Forest;
import com.dtflys.forest.config.ForestConfiguration;
import com.ehsy.common.ResponseVo;
import com.ehsy.config.MySuccessCondition3;
import com.ehsy.model.UserInfo;
import com.ehsy.service.SuccessfulCodeService;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;

/**
 * @author YanZhen_Li
 * @version 1.0
 * @title A11成功和失败条件
 * @description
 * @create 2024/6/18 16:59
 */
@SpringBootTest
        (webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
                properties = {"spring.config.location=classpath:success_when.yml"})
public class A11成功和失败条件 {
    @Resource
    SuccessfulCodeService service;
    /**
     * 我们可以自定义请求成功的状态码
     * 我认为我们在这里也可以自定义我们的消息体内的状态码，如是0则表示访问成功
     */
    @Test
    public void test1(){
        UserInfo user = new UserInfo("张三", "18", "男", "上海", "13812341234", "123@qq.com", "123456");
        String test1 = service.test01(200);
        String test2 = service.test02(550);
        // ? 第二种自定义全局配置响应的方法
        // 获取默认全局配置对象
        ForestConfiguration configuration = Forest.config();
        // MySuccessCondition 为您自定义的 SuccessWhen 实现类
        // 调用 setSuccessWhenClass 设置全局请求成功/失败条件类
        configuration.setSuccessWhenClass(MySuccessCondition3.class);
        ResponseVo<UserInfo> test3 = service.test03(user);

        System.out.println(test1);
        System.out.println(test2);
        System.out.println(test3);
    }
}
